package cn.itcast.service;

import cn.itcast.MemberDao;
import cn.itcast.MemberService;
import cn.itcast.pojo.Member;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service(interfaceClass = MemberService.class)
@Transactional
public class MemberServiceImpl implements MemberService {
    @Autowired
    MemberDao memberDao;


    @Override
    public boolean checkMemberByTelephone(String telephone) {
        Member byTelephone = memberDao.findByTelephone(telephone);
        if (byTelephone == null) {
            return false;
        }
        return true;
    }

    @Override
    public List<Integer> findMemberCountByMonth(List<String> mouths) {
        List<Integer> countList = new ArrayList<>();
        for (String mouth : mouths) {
            mouth = mouth + ".31";

            Integer count = memberDao.findMemberCountByMouth(mouth);
            countList.add(count);
        }

        return countList;
    }
}
